#include <iostream>
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <winsock2.h>

using namespace std;

int main()
{
    WSADATA wsa;
    WSAStartup(MAKEWORD(1,1),&wsa);

    SOCKET s;
    s=socket(AF_INET,SOCK_STREAM,0);

    struct sockaddr_in sa;
    memset(&sa,0,sizeof(sa));
    sa.sin_family=AF_INET;
    sa.sin_port=htons(2007);
    sa.sin_addr.s_addr=inet_addr("127.0.0.1");

    if(INVALID_SOCKET==connect(s,(struct sockaddr *)&sa,sizeof(sa)))
    {
        exit(0);
    }

    //IplImage *pImgOri=cvLoadImage("F:\\pineapple-video\\Debug\\4.jpg",-1);
    IplImage *pImgOri=0;

    CvCapture *pCap;
    pCap=cvCreateCameraCapture(1);
    if(pCap==0)
    {
        exit(-2);
    }

    while((pImgOri=cvQueryFrame(pCap)))
    {

        IplImage *pImg=cvCreateImage(cvSize(320,240),IPL_DEPTH_8U,3);

        cvResize(pImgOri,pImg);
        //cvSaveImage("output.bmp",pImg);

        send(s,pImg->imageData,pImg->width * pImg->height * 3,0);

        Sleep(100);

    }

    closesocket(s);

    cout << "Hello world!" << endl;
    return 0;
}
